<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //现有字符串如下 name1与value1为一组参数信息 name1表示为参数名value1表示为值 
        // 1、 从search字符串中 提取出name1参数的值  值为value1
        // 2、封装一个函数可以获取到指定参数的值
        var search = '?name1=value1&name2=value2&name3=value3&name4=value4&name5=value5';
        var arr = search.slice(1, search.length).split('&');
        var res = arr[0];
        console.log(res);

        function getUrlParams(key, str) {
            var arr = search.slice(1, search.length).split('&');
            var obj = {}
            arr.forEach(function(v,index){
                var temp = v.split('=')
                obj[temp[0]] = temp[1]

            });
            return console.log(obj[key]);
        }
        getUrlParams('name2', search);
    </script>
</body>

</html>